<template>
<div>
    <router-link to="/AddInvestInfo" style="margin-right:20px;">添加投资</router-link>
    <router-link to="/AddFinaninfo" style="margin-right:20px;">添加理财</router-link>
    <router-link to="/ShowFinaninfo" style="margin-right:20px;">显示理财</router-link>
    <router-link to="/AddBorrowMoney" style="margin-right:20px;">添加借款</router-link>
    <router-link to="/ShowBorrowMoney" style="margin-right:20px;">显示借款</router-link>
    <br>
    <h2 style="text-align: center;">显示投资项目</h2>
    <InvestCommon v-slot="info">
        <a href="#" @click="DeleteInfo(info.id)">删除</a>
        &nbsp;
        <a href="#" @click="EditInfo(info.id)">修改</a>
    </InvestCommon>
</div>
</template>

<script setup lang="ts">
import InvestCommon from './InvestCommon.vue'
import axios from 'axios';
import { useRouter } from 'vue-router';

const router=useRouter()

//完成投资项目删除
const DeleteInfo=(Iid:number)=>{
    if(confirm('确认删除数据吗?'))
    {
        axios.delete("https://localhost:44321/api/Invest/DeleteInvestInfo",
            {
                params:{
                    Iid:Iid
                }
            }
        )
        .then(res=>{
            if(res.data>0)
            {
                alert('删除成功');
                location.href="/ShowInvestinfo"
            }
            else if(res.data==-1)
            {
                alert('该项目已有人投资,无法删除');
            }
            else
            {
                alert('删除失败');
            }
        })
    }
}

//通过路由跳转到投资项目信息修改页面
const EditInfo=(Iid:number)=>{
    router.push({
        name:"EditInvestInfo",
        params:{
            Iid:Iid
        }
    })
}
</script>